//
//  MainViewController.swift
//  WeiboCY
//
//  Created by 林小陌 on 16/1/11.
//  Copyright © 2016年 林小陌. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
//按钮的监听事件
    //添加objc兼容OC
    @objc private func plusBtnDidClick(){
        print(__FUNCTION__)
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
      
        
        
        
        
      addChildViewControllers()
        
      let mainTabbar = MainTabbar()
        setValue(mainTabbar, forKey: "tabBar")
        mainTabbar.plusBtn.addTarget(self, action: "plusBtnDidClick", forControlEvents: .TouchUpInside)
    }
    private func addChildViewControllers() {
        addChildViewController(HomeTableViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(MessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        
        addChildViewController(DiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        
        addChildViewController(ProfileTableViewController(), imageName: "tabbar_profile", title: "我")
    }

   

    private func addChildViewController(vc: UIViewController,imageName: String,title: String) {
        
        //设置图片
        vc.tabBarItem.image = UIImage (named:imageName)
        //设置选中图片的颜色
//        vc.tabBarItem.selectedImage = UIImage (named: imageName+"_highlighted")?.imageWithRenderingMode(.AlwaysOriginal)
//        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
        self.tabBar.tintColor = UIColor.orangeColor()
        
        
        
        
        vc.title = title
        let nav = UINavigationController(rootViewController: vc)
        
        addChildViewController(nav)
    }
    
   
     
    
    
    

    

}
